<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>Layui</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <link rel="stylesheet" href="../../static/admin/css/layui.css"  media="all">
  <script type="text/javascript" src="../../static/news/js/jquery-1.12.4.min.js"></script>
  <!-- 注意：如果你直接复制所有代码到本地，上述css路径需要改成你本地的 -->
</head>
<body>


<form>
  <input id="csrf" value="{{ csrf_token() }}"/>
<div class="layui-upload-drag" id="test10" >
  <i class="layui-icon"></i>
  <p>点击上传，或将文件拖拽到此处</p>
  <div class="layui-hide" id="uploadDemoView">
    <hr>
    <img src="" alt="上传成功后渲染" style="max-width: 196px">
  </div>
</div>
</form>





<script src="../../static/admin/js/layui.js" charset="utf-8"></script>
<!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->
<script>
var a= $("#csrf").val()

layui.use('upload', function(){
  console.log(a)
  var $ = layui.jquery
  ,upload = layui.upload;

  //拖拽上传
  upload.render({
    elem: '#test10'
    ,headers:{
                'X-CSRFToken': a,
            }
    ,url: 'http://127.0.0.1:5000/admin/test_date' //改成您自己的上传接口
    ,done: function(res){
      layer.msg('上传成功');
      layui.$('#uploadDemoView').removeClass('layui-hide').find('img').attr('src', res.files.file);
      console.log(res)
    }
  });



});
</script>

</body>
</html>